package tech.abing.spider.task.pipeline.amac;

import java.util.List;

import org.apache.log4j.Logger;

import tech.abing.spider.component.Pipeline;
import tech.abing.spider.model.Proccessable;
import tech.abing.spider.task.model.amac.IntegrityPublicityEntity;
import tech.abing.spider.util.ProccessableUtil;
import tech.abing.spider.util.SqlUtil;

public class IntegrityPublicityPipeline implements Pipeline {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5767257371896214206L;
	private static Logger logger = Logger.getLogger(IntegrityPublicityPipeline.class);
	private static SqlUtil sqlUtil = null;
	
	public IntegrityPublicityPipeline(){
		if(sqlUtil == null){
			sqlUtil = SqlUtil.getInstance();
			logger.info("数据库连接创建成功！");
		}
	}

	@Override
	public void proccessData(List<Proccessable> objectContainer) {
		if(ProccessableUtil.instanceOfClass(objectContainer, IntegrityPublicityEntity.class)){//判断集合类型
			List<IntegrityPublicityEntity> list = ProccessableUtil.convert(objectContainer, IntegrityPublicityEntity.class);
			
			sqlUtil.batchInsert(sqlUtil.getConn(), IntegrityPublicityEntity.class, list);
		}
	}

	@Override
	public void destory() {
		if(sqlUtil != null){
			sqlUtil.closeConn();
			sqlUtil = null;
			logger.info("数据库连接关闭成功！");
		}
	}

}
